<?php

namespace app\api\controller;

use app\common\controller\Api;
use \app\common\model\LoanCompany;
use \app\common\model\Carousel;

/**
 * 首页接口
 */
class Jd extends Api
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页数据
     */
    public function getProductData()
    {
        $data = [];
        $page = input('get.page/s',1);
        $model = new LoanCompany();
        $res = $model->paginate(6,'',['page'=>$page]);
        $res1 = $model->select();
        foreach ($res as $k=>$v){
            $dataList[$k]['id'] = $v['id'];
            $dataList[$k]['pro_name'] = $v['pro_name'];
            $dataList[$k]['pro_pic_url'] = $v['image'];
            $dataList[$k]['prompt_msg'] = $v['prompt_msg'];
            $dataList[$k]['lenders_number'] = $v['lenders_number'];
            $dataList[$k]['monthly_interest_rate'] = $v['monthly_interest_rate'];
            $dataList[$k]['lending_time'] = $v['time_lending'];
            $dataList[$k]['loan_amount'] = $v['loan_amount'];
            $dataList[$k]['pro_link'] = $v['pro_link'];
            $data['dataList'] = $dataList;
        }
        $data['valid'] = 1;
        $data['count'] = count($res1);

        if ($res) {
            $this->success('成功', $data, '1000');
        } else {
            $this->success('失败', '', '1001');
        }
    }
    /**
     * 超市数据
     */
    public function getcateproductdata()
    {
        $data = [];
        $page = input('get.page/s',1);
        $cate_id = input('get.cate_id');
        $model = new LoanCompany();
        $res = $model
            ->where('cate_id','like','%'.$cate_id.'%')
            ->paginate(6,'',['page'=>$page]);
        $res1 = $model
            ->where('cate_id','like','%'.$cate_id.'%')
            ->select();
        foreach ($res as $k=>$v){
            $dataList[$k]['id'] = $v['id'];
            $dataList[$k]['pro_name'] = $v['pro_name'];
            $dataList[$k]['pro_pic_url'] = $v['image'];
            $dataList[$k]['prompt_msg'] = $v['prompt_msg'];
            $dataList[$k]['lenders_number'] = $v['lenders_number'];
            $dataList[$k]['monthly_interest_rate'] = $v['monthly_interest_rate'];
            $dataList[$k]['lending_time'] = $v['time_lending'];
            $dataList[$k]['loan_amount'] = $v['loan_amount'];
            $dataList[$k]['pro_link'] = $v['pro_link'];
            $data['dataList'] = $dataList;
        }
        $data['valid'] = 1;
        $data['count'] = count($res1);

        if ($res) {
            $this->success('成功', $data, '1000');
        } else {
            $this->success('失败', '', '1001');
        }
    }

    /**
     * 轮播图数据
     */
    public function Carousel(){
        $model = new Carousel();
        $res = $model
            ->select();
        foreach ($res as $k=>$v){
            $dataList[$k]['pic_name'] = $v['pic_name'];
            $dataList[$k]['pic_url'] = $v['image'];
            $dataList[$k]['url'] = $v['url'];
            $data['carousel'] = $dataList;
        }
        if ($res) {
            $this->success('成功', $data, '1000');
        } else {
            $this->success('失败', '', '1001');
        }
    }
}
